﻿@model DAMS.Web.Areas.Manage.Models.CategoryEditViewModel

@{
    ViewData["Title"] = "修改分类";
}
@section Stylesheets {
    
    <script src="~/lib/editor/kindeditor-all.js"></script>
}


<h5>修改分类</h5>
<hr />

<form asp-action="Edit">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <input type="hidden" asp-for="ID"/>
    <div class="form-group form-row">
        <label asp-for="ParentCategoryName" class="col-2 text-right col-form-label"></label>
        <div class="col-8">
            <span class="form-control">@Html.Raw(Model.ParentCategoryName)</span>
        </div>
    </div>
    <div class="form-group form-row">
        <label asp-for="Name" class="col-2 text-right col-form-label"></label>
        <div class="col-8"><input asp-for="Name" class="form-control" /></div>
        <span asp-validation-for="Name" class="text-danger form-text"></span>
    </div>
    <div class="form-group form-row">
        <label asp-for="Type" class="col-2 text-right col-form-label"></label>
        <div class="col-9 form-check form-check-inline">
            @foreach (var item in Html.GetEnumSelectList<DAMS.Models.CategoryType>(30))
            {
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" asp-for="Type" id="@("Type" + item.Value)" dataTypeChecked="@((int)Model.Type)" value="@item.Value">
                    <label class="form-check-label" for="@("Type" + item.Value)">@item.Text</label>
                </div>
            }
        </div>
        <span asp-validation-for="Type" class="text-danger form-text"></span>
    </div>
    <div class="form-group form-row">
        <label asp-for="ShowType" class="col-2 text-right col-form-label"></label>
        <div class="col-9 form-check form-check-inline">
            @foreach (var item in Html.GetEnumSelectList<DAMS.Models.CategoryShowType>())
            {
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="checkbox" id="@("ShowType" + item.Value)" name="ShowType" datachecked="@Model.ShowType" value="@item.Value">
                    <label class="form-check-label" for="@("ShowType" + item.Value)">@item.Text</label>
                </div>
            }
        </div>
        <span asp-validation-for="ShowType" class="text-danger form-text"></span>
    </div>
    <div class="form-group form-row">
        <label asp-for="Template" class="col-2 text-right col-form-label"></label>
        <div class="col-4 form-inline">
            <input asp-for="Template" type="text" class="form-control" />
            <select class="form-control form-inline" id="TemplateList"></select>
            <span asp-validation-for="Template" class="text-danger form-text"></span>
        </div>
    </div>
    <div class="form-group form-row">
        <label asp-for="ArticleTemplate" class="col-2 text-right col-form-label"></label>
        <div class="col-4 form-inline">
            <input asp-for="ArticleTemplate" type="text" class="form-control" />
            <select class="form-control form-inline" id="ArticleTemplateList"></select>
            <span asp-validation-for="ArticleTemplate" class="text-danger form-text"></span>
        </div>
    </div>
    <div class="form-group form-row">
        <label class="col-2 text-right col-form-label" asp-for="HtmlDescription"></label>
        <div class="col-6">
            <input asp-for="HtmlDescription" type="text" class="form-control" />
        </div>
        <span asp-validation-for="HtmlDescription" class="text-danger form-text"></span>
    </div>
    <div class="form-group form-row">
        <label class="col-2 text-right col-form-label" asp-for="HtmlKeyWord"></label>
        <div class="col-6 ">
            <input asp-for="HtmlKeyWord" type="text" class="form-control" />

        </div>
        <span asp-validation-for="HtmlKeyWord" class="text-danger form-text"></span>
    </div>
    <div class="form-group form-row">
        <label asp-for="Content" class="col-2 text-right col-form-label"></label>
        <div class="col-10"><textarea asp-for="Content" style="width:90%;"></textarea></div>
        <span asp-validation-for="Content" class="text-danger form-text"></span>
    </div>

    <div class="form-group form-row">
        <label class="col-2 text-right col-form-label"></label>
        <div class="col-4 ">
            <input type="submit" value="修改" class="btn btn-primary w-25" />

        </div>
    </div>
</form>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    <script src="~/lib/zTree/js/jquery.ztree.all.js"></script>
    <script>

        $(document).ready(function () {
            var templates =@Html.Raw(Model.TemplatesJson);
            var options = {
                //cssPath: '/css/index.css',
                filterMode: true,
                minHeight: 300,
                themeType: 'default',
                uploadJson: '/Manage/Home/UpLoadFile',
                fileManagerJson: '/Manage/Home/UpLoadFileManage',
                allowFileManager: true
            };
            var editor = KindEditor.create('#Content', options);
            $("input[datachecked]").each(function () {
                var s = $(this).attr('datachecked');
                var t = $(this).val();
                if ((s | t) == s)
                    $(this).prop('checked', true);

            })
            $("input[dataTypeChecked]").each(function () {
                var s = $(this).attr('dataTypeChecked');
                var t = $(this).val();
                if (s == t)
                    $(this).prop('checked', true);
                switch (s) {
                    case '2'://首页
                        $("#TemplateList").html("<option value=''>请选择列表页模板</option><option>" + templates.home.join("</option><option>") + "</option>");
                        $("#ArticleTemplate").prop('disabled', false).prop('readonly', true);
                        $("#ArticleTemplateList").prop('disabled', true);
                        $("#Template").prop('readonly', true);
                        editor.readonly();
                        break;
                    case '4'://分类
                        $("#TemplateList").html("<option value=''>请选择列表页模板</option><option>" + templates.list.join("</option><option>") + "</option>").prop('disabled', false);
                        $("#ArticleTemplateList").html("<option value=''>请选择内容页模板</option><option>" + templates.article.join("</option><option>") + "</option>");
                        $("#ArticleTemplate").prop('disabled', false).prop('readonly', true);
                        $("#Template").prop('readonly', true);
                        break;
                    case '8'://单页
                        $("#TemplateList").html("<option value=''>请选择单页模板</option><option>" + templates.page.join("</option><option>") + "</option>").prop('disabled', false);
                        $("#ArticleTemplate").prop('disabled', true);
                        $("#ArticleTemplateList").prop('disabled', true);
                        $("#Template").prop('readonly', true);
                        break;
                    case '16'://链接
                        $("#TemplateList").prop('disabled', true);
                        $("#ArticleTemplate").prop('disabled', true)
                        $("#ArticleTemplateList").prop('disabled', true);
                        editor.readonly();
                        break;
                }
                $(this).prop('disabled', true);
            });
            //模版选择
            $("#TemplateList").change(function () {
                $("#Template").val($("#TemplateList").val());
            });
            $("#ArticleTemplateList").change(function () {
                $("#ArticleTemplate").val($("#ArticleTemplateList").val());
            })


        })
       

       
    </script>
}